using UnityEngine;

public class VehicleSelection : MonoBehaviour
{
	public VehicleConfiguration VehicleConfiguration;

	public Settings Settings;

	public RCCCarCamera Camera;

	public GameObject[] vehicles;

	private RCCCarControllerV2 CarController;

	public bl_MiniMap minimap;

	public GameObject[] vehicle_arrows;

	private void Start()
	{
		SelectVehicle();
	}

	public void SelectVehicle()
	{
		int num = 0;
		GameObject[] array = vehicles;
		foreach (GameObject gameObject in array)
		{
			if (num == VehicleConfiguration.GetSelectedVehicle())
			{
				gameObject.SetActive(value: true);
				Camera.playerCar = gameObject.transform;
				ConfigureVehicle(gameObject);
			}
			num++;
		}
	}

	public void ConfigureVehicle(GameObject vehicle)
	{
		CarController = (RCCCarControllerV2)vehicle.GetComponent(typeof(RCCCarControllerV2));
		CarController.maxspeed = VehicleConfiguration.GetSpeed();
		CarController.engineTorque = VehicleConfiguration.GetAcceleration();
		if (PlayerPrefs.GetInt("vehicle_" + VehicleConfiguration.GetSelectedVehicle() + "_acceleration_upgraded", 0) >= 1)
		{
			CarController.gearShiftingDelay = 0.1f;
		}
		CarController.brake = VehicleConfiguration.GetBrakes();
		if (Settings.GetControls() == 0)
		{
            CarController.useAccelerometerForSteer = true;
        }
		else if (Settings.GetControls() == 1)
		{
			CarController.useAccelerometerForSteer = false;
			CarController.steeringWheelControl = false;
		}
		else
		{
            CarController.steeringWheelControl = true;
        }
	}
}
